#include <gl/glfw.h>
#include "guimgr.h"
#include "guiwindow.h"
#include "math.h"
#include <vector>

CGuiManager* g_pGuiManager = NULL;
CGuiWindow* g_pTestWindow = NULL;
CGuiWindow* g_pTestWindow2 = NULL;
CInputManager* g_pInputManager = NULL;

int32_t main(int32_t argc, uint8_t **argv)
{
	glfwInit();

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_POINT_SMOOTH);
	glEnable(GL_LINE_SMOOTH);

	glEnable(GL_BLEND);
	glEnable(GL_ALPHA_TEST);

	bool running = true;

	g_pGuiManager = new CGuiManager;
	g_pTestWindow = new CGuiWindow;
	g_pTestWindow2 = new CGuiWindow;
	g_pInputManager = new CInputManager;
	vec2f winPos;
	vec2f winDim;

	winPos.x = 0;
	winPos.y = 0;
	winDim.x = 100;
	winDim.y = 120;
	std::string caption("Console Window");
	g_pTestWindow->Initialize(winPos, winDim, caption);
	winPos.x = 50;
	winPos.y = 50;
	winDim.x = 250;
	winDim.y = 200;
	g_pTestWindow2->Initialize(winPos, winDim, caption);
	
	g_pGuiManager->AddWindow(g_pTestWindow);
	g_pGuiManager->AddWindow(g_pTestWindow2);

	if(!glfwOpenWindow(800, 600, 8, 8, 8, 8, 24, 8, GLFW_WINDOW))
	{
		glfwTerminate();
		return 0;
	}

	glfwSetWindowTitle("Digital Hemorrhage GUI");

	while(running)
	{	
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
		running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
		g_pInputManager->Update();
		g_pGuiManager->Update();
		
		g_pGuiManager->Render();
		g_pInputManager->UpdateMouse();
		glfwSwapBuffers();
	}

	glfwTerminate();

	return 0;
}
